package com.SunSoft.PhoneRemoteControl;

import android.app.Dialog;
import android.os.Handler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

final class ga
  implements Runnable
{
  public final void run()
  {
    while (true)
    {
      int k;
      Object localObject3;
      try
      {
        Object localObject2;
        if (fy.h(this.a) == 2)
          localObject2 = new URL(fy.i(this.a));
        for (Object localObject1 = fy.j(this.a); ; localObject1 = fy.l(this.a))
        {
          localObject2 = (HttpURLConnection)((URL)localObject2).openConnection();
          ((HttpURLConnection)localObject2).connect();
          int j = ((HttpURLConnection)localObject2).getContentLength();
          localObject2 = ((HttpURLConnection)localObject2).getInputStream();
          localObject3 = new File(fy.m(this.a));
          if (!(((File)localObject3).exists()))
            ((File)localObject3).mkdir();
          localObject1 = new FileOutputStream(new File((String)localObject1));
          localObject3 = new byte[1024];
          int i = 0;
          k = ((InputStream)localObject2).read(localObject3);
          i += k;
          fy.a(this.a, (int)(i / j * 100.0F));
          fy.n(this.a).sendEmptyMessage(1);
          if (k > 0)
            break label270;
          if (fy.o(this.a) != null)
            fy.o(this.a).dismiss();
          if (fy.h(this.a) != 2)
            break;
          fy.n(this.a).sendEmptyMessage(3);
          ((FileOutputStream)localObject1).close();
          ((InputStream)localObject2).close();
          return;
          localObject2 = new URL(fy.k(this.a));
        }
        fy.n(this.a).sendEmptyMessage(2);
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        return;
      }
      label270: localException.write(localObject3, 0, k);
      boolean bool = fy.p(this.a);
      if (!(bool))
        continue;
    }
  }
}